package com.ruoyi.teaching.service.impl;

import java.util.List;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.teaching.domain.Task;
import com.ruoyi.teaching.mapper.StudentMapper;
import com.ruoyi.teaching.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.StageTaskMapper;
import com.ruoyi.teaching.domain.StageTask;
import com.ruoyi.teaching.service.IStageTaskService;

/**
 * 阶段任务Service业务层处理
 *
 * @author sunshine
 * @date 2024-01-23
 */
@Service
public class StageTaskServiceImpl implements IStageTaskService
{
    @Autowired
    private StageTaskMapper stageTaskMapper;
    @Autowired
    private ITaskService taskService;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询阶段任务
     *
     * @param id 阶段任务主键
     * @return 阶段任务
     */
    @Override
    public StageTask selectStageTaskById(Long id)
    {
        return stageTaskMapper.selectStageTaskById(id);
    }

    /**
     * 查询阶段任务列表
     *
     * @param stageTask 阶段任务
     * @return 阶段任务
     */
    @Override
    public List<StageTask> selectStageTaskList(StageTask stageTask)
    {
        return stageTaskMapper.selectStageTaskList(stageTask);
    }

    /**
     * 新增阶段任务
     *
     * @param stageTask 阶段任务
     * @return 结果
     */
    @Override
    public int insertStageTask(StageTask stageTask)
    {
        stageTaskMapper.insertStageTask(stageTask);
         List<String> names = studentMapper.selectStudentByName();
         for (int i = 0; i < names.size(); i++) {
         Task task = new Task();
         task.setFinishStatus(0);
         task.setStageTaskName(stageTask.getStageTaskName());
         task.setStageId(stageTask.getId());
         task.setTaskDescribe(stageTask.getStageTaskDescribe());
         task.setClassId("java38");
         task.setStatus(0);
         task.setStudentId(names.get(i));
         taskService.insertTask(task);

        }

        return 1;
    }

    /**
     * 修改阶段任务
     *
     * @param stageTask 阶段任务
     * @return 结果
     */
    @Override
    public int updateStageTask(StageTask stageTask)
    {
        return stageTaskMapper.updateStageTask(stageTask);
    }

    /**
     * 批量删除阶段任务
     *
     * @param ids 需要删除的阶段任务主键
     * @return 结果
     */
    @Override
    public int deleteStageTaskByIds(Long[] ids)
    {
        return stageTaskMapper.deleteStageTaskByIds(ids);
    }

    /**
     * 删除阶段任务信息
     *
     * @param id 阶段任务主键
     * @return 结果
     */
    @Override
    public int deleteStageTaskById(Long id)
    {
        return stageTaskMapper.deleteStageTaskById(id);
    }

    @Override
    public List<Task> selectStageTaskList1(Task task) {
        return taskService.selectTaskList1(task);
    }
}
